<?php 
	
	include("../classes/bBitwise.class.inc");
	include("../classes/bArray.class.inc");
	include("../classes/bXml.class.inc");
	
$xsl =<<<EOX
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>

	<xsl:template match="/">

		<br /><b>And I quote: 'A simple <i>g<xsl:value-of select="/a/b/c/f/ido/g" /> this is cool</i>, will do.'</b><br />

	</xsl:template>
</xsl:stylesheet>
EOX;

	$u =dom_import_simplexml(simplexml_load_string("<b />"));
	
	echo $u->nodeName;
	$xx = new bXml("<a href='clone'><b><c><d></d><e placate='yes'><![CDATA[cool]]></e><f></f></c></b></a>"); 
	$b = new bXml("<x><y /><z>oo</z></x>");

	$x =$xx->CloneNode();
	
	$ns = new bXml("
	<jones>
		<nick>
			<johns>whoa</johns>
			<johns>when</johns>
			<his>middlename</his>
			<life>partner</life>
			<johns>likey</johns>
		</nick>
	</jones>
	");
	
	$j = new bXml("/lomo verde", bXml::AUTO_WRAP);
	$z = new bXml('file://'.dirname(__FILE__).'/testxml.xml');
	
	$ans = $ns->nick->xpath('*[name() ="his" or name()="johns"]');
	var_dump($ans);
	echo "<br /><br />";
	foreach($ns->nick as $oooo) {
		var_dump($oooo);
	}
	
	print_r("<div style='color:tan'>".htmlentities($j->asXml())."</div>");
	print_r("<div style='color:gold'>".htmlentities($z->asXml())."</div>");
	print_r(htmlentities($ns->asXml()));
	
	echo $ns->nick->johns;
	
//	$x->b->c->d->AddCData("Hello");
	$x->b->c->d->AddComment(" I like this ");
	$x->b->AddChild("u");
	
	$x->AddAttribute('w','3c');
	$b->AddAttribute('s', 'md')->AddAttribute('dodger','lo')->AddChild('LA', 'baby');	
	$b->y->gosh ="cool";
	$b->y->gosh[1] ="notcool";
	$y11= "y";
	$gosh11 ="gosh";
	
	echo ":::".$b->{$y11}->{$gosh11}.":::";
	echo ":::".$b->{$y11}->{$gosh11}[1].":::";
	
//	print_r($x->b->c);
	echo "<br /><br />";
	echo "1 "; print_r($o =$x->pathFinder()); echo "<br /><br />";
	echo "2 "; print_r($o =$x->b->pathFinder());echo "<br /><br />";
	echo "3 "; print_r($o =$x->b->c->pathFinder());echo "<br /><br />";
	echo "4 "; print_r($o =$x->b->c->e->pathFinder());echo "<br /><br />";
	echo "<br />".htmlentities($x->asXMl())."<br /><br .>";
	echo "5 "; $x->b->c->f->AddChild("<ido jk='kj'></ido>")->AddChild("p", "p");
	echo "6 "; $x->b->c->f->ido->AddChild("g", "ee whiz")->insertBefore('<babyface />');
	echo "6.5"; $x->b->c->f->insertBefore('<due><while></while></due>')->addchild('s');
	$x->b->c->removeChild($x->b->c->due);

	echo "7"; $x->b->c->AddChild("h","")->AddChild("<bud wise='er'>I like it dude</bud>")->AddChild("woah", "holdup");
	echo "<br />----<br />";
	
	$x->AddChild("<oo><p>mm</p><p>ll</p><p>yy</p><p>ss</p></oo>");
	$x->oo->p[0]->ReplaceWith('<d>ww</d>');
	
	echo "position: ".$x->oo->d[0]->Position()." is ".(string)$x->oo->d->Position(1)."<br />";
	
	foreach($x->oo->p as $gee=>$funk) {
		echo "POS:[".(string)$funk."]".$funk->Position()."<br />";
	}
	
//	$ns->AddChild('b')->b->AddChild("o")->o->AddChild("k", "first one"); // Broken ... should get the child back
	$ns->AddChild('b')->AddChild("o")->AddChild("k", "first one");
	$ns->b->o->addChild("k", "2nd one");
	$ns->b->o->addChild("k", "#3 is here");
	
	echo "<div style='color:blue'>H: ".htmlentities($x->oo->lastChild()->AsXml())."</div>";
	
	echo htmlentities($ns->AsXml());
	echo "<br />----<br/>";
	foreach($ns->b->o as $xo){
		foreach($xo->k as $k=>$v) {
		
			echo "key: $k -> value: $v<br />";
	//		$v->AddChild('lo','key');
			$v->NodeValue((string)$v.'.YoYoMa');
		}
	}
	
	foreach($ns->nick->johns as $k=>$v) {
		
		echo "key: $k -> value: $v<br />";
	}
	
	$x->oo->WrapWithNode('<ss />');
	echo htmlentities($x->AsXml());
	echo "<br /><br />";
	echo htmlentities($ns->AsXml());
	echo "<br />----<br/>";
	echo htmlentities($b->AsXml());
	echo "<br /><br />";
//	print_r($x->AsArray());
	
	$jj ="<x:root xmlns:x='http://abc123.com'><x:path><x:will><x:work>Yes!!</x:work></x:will></x:path></x:root>";
	$gg ="<root xmlns='http://abc123.com'><path><will><work xmlns='http://dudeyourock'>Yes!!</work></will></path></root>";
	
	$g =new bXml($jj);
	$j =new bXml($gg);
	
	$g->registerXPathNamespace("aa", "http://abc123.com");
	
//	echo var_dump($g->path->NodeName());
	echo "<br />".$j->path->will->work->PathFinder();
	echo htmlentities($g->AsXml());
	echo "<br /><br />";
	echo htmlentities($xx->AsXml());
	echo "<br /><br />";	
	echo $x->transformwith($xsl)->AsHtml();
	echo htmlentities($x->AsXml());
	print_r($x->b->c->f->asJson()); echo "<br /><br />";
	echo "aa;<br />";
	print_r($u = $x->asArray());	

	// Note this interface is not needed, because they will have the IbXml interface
	// for determining what baisc Type of XML object your working with.
	interface ImyXml {}
	
	class myXml extends bXml implements ImyXml {
		
		protected $bSimpleXml ='mySimpleXml';
		protected $bXml ='myXml';

		public static function Load($mXml, $bAutoWrap =false) {
			$aVars = get_class_vars(__CLASS__);
				
			$aArguments =func_get_args();
			$aArguments[1] =$bAutoWrap;
			$aArguments[2] =(isset($aArguments[2]) ? $aArguments[2] : $aVars['bSimpleXml']);
			$aArguments[3] =(isset($aArguments[3]) ? $aArguments[3] : $aVars['bXml']);
			
			return call_user_func_array(array('bXml',__FUNCTION__), $aArguments);
		}
		
		public function ToXml($mXml, $bAutoWrap =false) {
			$aVars = get_class_vars(__CLASS__);
				
			$aArguments =func_get_args();
			$aArguments[1] =$bAutoWrap;
			$aArguments[2] =(isset($aArguments[2]) ? $aArguments[2] : $aVars['bSimpleXml']);
			
			return call_user_func_array(array('bXml',__FUNCTION__), $aArguments);
		}
	}
	
	class mySimpleXml extends bSimpleXml implements ImyXml {}
	
	
	$k = new myXml("<wow i='1'><this i='to'><is>now</is></this></wow>");
	echo "<br /><br />";
	var_dump($k);
	echo "<br />";
	var_dump($k->this);

	$bwwn = $b->wrapWithNode("<camel />");
	var_dump(htmlentities($bwwn->asXml())); echo "<br /><br />";
	echo "<br />bb;</br />";
	$o = new myXml(array("wow"=>array("this"=>array("is"=>"now"))));
	echo "a<br />";
	var_dump(htmlentities($o->asXml()));
		echo "<br />cc;<br />";	
//	echo "<br />";
//	var_dump($u);
//	$j = new myXml($u);
	
//	print(htmlentities($j->asXml()));
//	var_dump($k['i']);
	
	echo (int)isset($k['b']);  echo "<-- \$k <br /><br />";
	echo (int)isset($k->this); echo "<-- \$o ";
	
?>